package com.eleadmin.common.system.controller;
import com.eleadmin.common.system.param.Goods;
import com.eleadmin.common.system.param.req.GoodsRequest;
import com.eleadmin.common.system.param.result.PageResult;
import com.eleadmin.common.system.param.result.Result;
import com.eleadmin.common.system.service.GoodsSercice;
import com.eleadmin.util.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/Goods")
public class GoodsController {
    @Autowired
    GoodsSercice goodsSercice;

    /**
     * 列表
     * @param goodsRequest
     * @return
     */
    @PostMapping("/list")
    public Result<PageResult<Goods>> list(@RequestBody GoodsRequest goodsRequest){
        Result<PageResult<Goods>> list=goodsSercice.list(goodsRequest);
        return list;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/goodsDel")
    public Result goodsDel(@RequestParam Integer id){
        Result result=goodsSercice.goodsDel(id);
        return result;
    }

    /**
     * 新增
     */
    @PostMapping("/goodsAdd")
    public Result goodsAdd(@RequestBody Goods goods){
        Result result=goodsSercice.goodsAdd(goods);
        return result;
    }

    /**
     * 普通导出
     * @param response
     */
    @GetMapping("/Districtout")
    public void goodsNormal(HttpServletResponse response){
        List<Goods> list=goodsSercice.Districtout();

        ExcelUtil<Goods> goodsExcelUtil = new ExcelUtil<>(Goods.class);

        goodsExcelUtil.exportExcel(response,list,"商品管理");
    }
}
